<template>
  <div>
    <div
      class="add"
      @click="add()"
      v-if="(rightValue & 1) > 0"
    >新增</div>
    <eagle-page-list
      ref="eaglePageList"
      @bindData="bindData"
      :queryParams="queryParams"
      :controller="controller"
      placeholder="请输入事故名称,事故编号搜索"
      :conditions="conditions"
      :pageSize="20"
    >
      <div slot="list">
        <eagle-cell
          style="margin-top: 10px"
          class="br-8"
          v-for="(item, index) in list"
          :key="index"
        >
          <div>
            <div @click="views(item)">
              <eagle-row
                gutter="15"
                style="word-break:break-all"
              >
                <eagle-col>
                  <b style="font-size: 13px">{{ item.AccidentName }}</b>
                </eagle-col>
              </eagle-row>

              <eagle-row gutter="15">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />事故编号：{{ item.IncidentNumber }}
                </eagle-col>
              </eagle-row>
              <!-- <van-row gutter="20">
                                <van-col style="word-break:break-all" >
                                    <img class="icon" src="@/assets/Images/AppIcon/icon_list_type.png" />事故名称:{{ item.AccidentName }}
                                </van-col>
                            </van-row> -->

              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                  />事故发生日期：{{ item.AccidentDate | formatDateTime }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />事故分类：{{ item.AttidentClassification }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />事故分级：{{ item.AttidentgRading }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />潜在风险：{{ item.PotentialRisk }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_user.png"
                  />创建人：{{ item.CreateChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                  />创建日期：{{ item.CreateDate | formatDateTime }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />区域部门：{{ item.AccidentDepartmentName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />状态：{{ getStatus(item.Status) }}
                </eagle-col>
              </eagle-row>
              <van-divider />
            </div>

          </div>
          <div class="op_btn">
            <div
              class="btn_item"
              v-if="(rightValue & 1) > 0&&item.Status ==0"
              @click="edit(item)"
            >
              <img
                src="@/assets/Images/AppIcon/icon_list_edit.png"
                alt=""
              />
              <div class="mr-10">编辑</div>
            </div>
            <div
              class="btn_item"
              v-if="(rightValue & 2) > 0&&item.Status ==0"
              @click="deletePlan(item)"
            >
              <img
                src="@/assets/Images/AppIcon/icon_list_delete.png"
                alt=""
              />
              <div class="mr-10">删除</div>
            </div>
            <div
              class="btn_item"
              v-if="(rightValue & 8) > 0&&item.Status ==10"
              @click="deletePlan(item)"
            >
              <img
                src="@/assets/Images/AppIcon/icon_list_delete.png"
                alt=""
              />
              <div class="mr-10">删除</div>
            </div>
            <div
              class="btn_item"
              @click="goApprove(item)"
            >
              <img
                src="@/assets/Images/AppIcon/icon_list_edit.png"
                alt=""
              />
              <div class="mr-10">审批历史</div>
            </div>
          </div>
        </eagle-cell>
      </div>
    </eagle-page-list>
  </div>
</template>
<script>
import { getMenuByMenuCode } from "@/api/common";
export default {
  data() {
    return {
      list: [],
      searchValue: "",
      conditions: {},
      controller: "/WhAccidentInitialReport",
      queryParams: {
        dataType: "List",
        keywords: "",
      },
      rightValue: 0,
      userChooseDialogShow1: false,
    };
  },
  created() {
    this.getMenuByMenuCode();
  },
  mounted() {},
  methods: {
    getStatus(val) {
      if (val == 0) {
        return "未提交";
      } else if (val == 5) {
        return "审批中";
      } else {
        return "已审批";
      }
    },
    bindData(data) {
      this.list = [];
      if (data) {
        this.list = data;
      }
    },
    getMenuByMenuCode() {
      var me = this;
      getMenuByMenuCode("WH_AccidentInitialReport_List").then((res) => {
        me.rightValue = res.data ? res.data.RoleRightValue : 0;
      });
    },
    deletePlan(item) {
      //初始报告删除
      const that = this;

      that.$dialog
        .confirm({
          title: "询问",
          message: "您确定要删除该事故报告吗？",
        })
        .then(() => {
          that.$axios
            .get("/WhAccidentInitialReport/Delete", { params: { id: item.ID } })
            .then((res) => {
              that.$toast.success("删除成功！");
              setTimeout(() => {
                that.$refs.eaglePageList.search({});
              }, 300);
            });
        })
        .catch(() => {
          // on cancel
        });
    },
    goApprove(item) {
      this.$router.push({
        path: "/AccidentInitReportApprove",
        query: {
          recordID: item.ID,
          opController: "WhAccidentInitialReport",
        },
      });
    },
    edit(item) {
      //初始报告编辑
      if (item.ID > 0) {
        this.isEdit = true;
      } else {
        this.isEdit = false;
      }
      this.$router.push({
        path: "/whAccidentInitialReportDetail",
        query: { id: item.ID },
      });
    },
    add() {
      this.$router.push({
        path: "/whAccidentInitialReportDetail",
        query: { type: "add" },
      });
    },
    views(item) {
      this.$router.push({
        path: "/whAccidentInitialReportView",
        query: { id: item.ID },
      });
    },
  },
};
</script>
<style lang="less" scoped>
.phone {
  position: relative;
  .code {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 12px;
  }
}
.register-info {
  background-color: #e8f1f8;
  padding-bottom: 20px;
}
.img-box {
  height: 50px;
  width: 50px;
  padding: 10px;
  position: absolute;
  left: 50%;
  top: 60px;
  background-color: #fff;
  border-radius: 50%;
  overflow: hidden;
}
.popup-title {
  line-height: 35px;
  padding: 10px;
  font-size: 15px;
  padding-left: 20px;
}

.op_btn {
  display: flex;
  justify-content: flex-end;
  .btn_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}

.search-box {
  height: 1rem;
}
</style>